Skip to content

Enhance array index handling and update RBS configuration#16

Merged
Syati merged 6 commits intomainfrom
feature/i18n_cofigure
May 1, 2026
Merged

Enhance array index handling and update RBS configuration#16
Syati merged 6 commits intomainfrom
feature/i18n_cofigure

Conversation

@Syati
Copy link
Copy Markdown
Owner

@Syati Syati commented May 1, 2026

This pull request introduces a new global configuration option to the StructuredParams gem, allowing users to control whether array indices in human attribute names and error messages are displayed as 0-based (default) or 1-based (human-friendly). The change is fully documented, covered by tests, and reflected in both code and type signatures. Additional improvements include minor RuboCop and type checking configuration updates, and dependency lockfile updates.

New Configuration Option and Usage:

  • Added a StructuredParams.configure interface with a array_index_base setting (default: 0, can be set to 1) to control whether array indices in error messages and human attribute names are 0-based or 1-based. This affects both API param error messages and form object full messages. [1] [2]
  • Updated the documentation (docs/installation.md) to explain the new configuration option, including usage examples and option descriptions. [1] [2]

i18n and Human Attribute Name Behavior:

  • Modified lib/structured_params/i18n.rb and its type signatures to use the configured array_index_base when displaying array indices in human attribute names and error messages, including in i18n templates. Documentation and inline comments have been updated accordingly. [1] [2] [3] [4] [5] [6] [7]
  • Added comprehensive tests to ensure correct behavior for both 0-based and 1-based indices, for both default and localized (e.g., Japanese) error messages. Also tests validation of the configuration value. [1] [2]

Type Signatures and RuboCop/Steep Configuration:

  • Updated RBS signatures to reflect the new configuration option and its API. [1] [2]
  • Added lib/structured_params.rb to RuboCop RBS exclusions and increased the allowed method length in .rubocop.yml. Suppressed errors from broken library RBS files in Steepfile. [1] [2] [3]

Dependency and Lockfile Updates:

  • Updated rbs_collection.lock.yaml to newer gem_rbs_collection revisions and made minor dependency version adjustments. [1] [2] [3] [4] [5] [6]

Other Improvements:

  • Improved documentation for permit_attribute_names in Type::Array for clarity.

These changes make StructuredParams more flexible and user-friendly, especially for applications targeting end-users who expect 1-based numbering in UI and error messages.

Summary by CodeRabbit

  • New Features

    • Added global configuration for StructuredParams with array_index_base (0 or 1) to control how array indices appear in labels and error messages.
  • Documentation

    • Installation guide updated with configuration instructions and array_index_base behavior and examples.
  • Tests

    • Added tests covering array_index_base behavior, validation, and locale-specific labeling.
  • Chores

    • Adjusted static analysis/type-checker and linter configurations; updated lockfile entries.

Copilot AI review requested due to automatic review settings May 1, 2026 06:05
@Syati Syati self-assigned this May 1, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a global StructuredParams configuration option to control whether array indices shown in human_attribute_name/error messages are displayed as 0-based (default) or 1-based, with corresponding docs, tests, and type signature updates.

Changes:

  • Introduce StructuredParams.configure/configuration/reset_configuration! and the array_index_base setting.
  • Apply array_index_base when formatting array indices in nested human attribute names (including i18n templates).
  • Update documentation, RBS signatures, and RuboCop/Steep configuration; refresh rbs_collection lockfiles.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/structured_params.rb Adds global configuration API and array_index_base setting.
lib/structured_params/i18n.rb Uses configured index base when rendering array indices in labels/i18n.
spec/i18n_spec.rb Adds specs for 0-based vs 1-based behavior and validation.
docs/installation.md Documents the new configuration option with examples.
sig/structured_params.rbs Updates public RBS API for configuration methods/options.
sig/structured_params/i18n.rbs Updates i18n module documentation in RBS.
sig/structured_params/type/array.rbs Clarifies permit_attribute_names behavior in RBS docs.
.rubocop.yml Adjusts RuboCop method length threshold.
.rubocop_rbs.yml Updates rubocop-rbs_inline exclusions.
Steepfile Suppresses library RBS diagnostic noise from gem_rbs_collection.
rbs_collection.yaml Minor YAML cleanup.
rbs_collection.lock.yaml Updates locked RBS collection revisions/dependencies.

Comment thread lib/structured_params.rb Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5984949506

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread Steepfile
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 055314be-34d5-41ba-a15c-486f7ab35c7d

📥 Commits

Reviewing files that changed from the base of the PR and between df0ad50 and bd79d35.

📒 Files selected for processing (2)
  • lib/structured_params.rb
  • spec/i18n_spec.rb
✅ Files skipped from review due to trivial changes (1)
  • spec/i18n_spec.rb
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/structured_params.rb

📝 Walkthrough

Walkthrough

Adds a global StructuredParams::Configuration with an array_index_base (0 or 1), exposes StructuredParams.configuration, .configure, and .reset_configuration!, updates i18n label generation to use the configured index base, and includes RBS, docs, test, and tooling configuration updates.

Changes

Cohort / File(s) Summary
Linter & RBS/Type tooling
\.rubocop\.yml, \.rubocop_rbs\.yml, Steepfile
Increased RuboCop MethodLength threshold, excluded lib/structured_params.rb from an RBS inline rule, and suppressed a Steep diagnostic for the :lib target.
Core feature & API
lib/structured_params.rb, lib/structured_params/i18n.rb
Added StructuredParams::Configuration with array_index_base (validated to 0 or 1), singleton configuration accessors (configuration, configure, reset_configuration!), moved type registration helpers into module singleton, and updated i18n display index computation to use the configured base.
Type signatures
sig/structured_params.rbs, sig/structured_params/i18n.rbs, sig/structured_params/type/array.rbs
Declared Configuration in RBS and module-level configuration methods; updated i18n and array type inline docs to reflect the array index base behavior and permit rules.
Documentation
docs/installation.md
Added configuration usage example and array_index_base option docs (default 0) with explanatory notes.
Tests
spec/i18n_spec.rb
Added tests that reset configuration after each example; added spec coverage for array_index_base behavior (0 vs 1), locale handling, and validation of the setter.
Dependency lock & metadata
rbs_collection.lock.yaml, rbs_collection.yaml
Updated git revisions for multiple gems, changed bigdecimal source/version, switched logger source, added random-formatter, and bumped rspec-parameterized-core. Small YAML whitespace edit.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nudged a config, small and neat,
Numbers jump from zero to one — what a feat!
I18n now counts how I desire,
Tests hop in to stoke the fire. 🥕✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Enhance array index handling and update RBS configuration' directly and accurately summarizes the main changes: adding configurable array index handling (0-based vs 1-based) and updating RBS/type configuration across the codebase.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/i18n_cofigure

Review rate limit: 8/10 reviews remaining, refill in 7 minutes and 11 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
.rubocop.yml (1)

33-34: ⚡ Quick win

Prefer local cop suppression over a global MethodLength relaxation.

Raising this globally weakens method-size guardrails across the whole codebase for a single hotspot. Keep the project default stricter and suppress only where needed.

Proposed change
 Metrics/MethodLength:
-  Max: 25
+  Max: 20
# In lib/structured_params/i18n.rb, around build_nested_label
# rubocop:disable Metrics/MethodLength
def build_nested_label(result, index, attr_human, options)
  # ...
end
# rubocop:enable Metrics/MethodLength
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.rubocop.yml around lines 33 - 34, Don't relax Metrics/MethodLength
globally; instead keep the Max: 25 default and add a local suppression around
the long method. Edit the long method build_nested_label in
lib/structured_params/i18n.rb and wrap it with a rubocop disable/enable pair
(rubocop:disable Metrics/MethodLength ... rubocop:enable Metrics/MethodLength)
so only build_nested_label is exempt while the global cop remains strict.
.rubocop_rbs.yml (1)

12-15: ⚡ Quick win

Scope the RBS inline exclusion more narrowly.

Excluding the entire file reduces type-safety signal for future additions in lib/structured_params.rb. Prefer targeted inline disable only where the cop misfires.

Proposed change
 Style/RbsInline/UntypedInstanceVariable:
   Exclude:
     - 'lib/structured_params/params.rb'
-    - 'lib/structured_params.rb'
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.rubocop_rbs.yml around lines 12 - 15, Remove the broad file-level exclusion
for the Style/RbsInline/UntypedInstanceVariable cop and instead scope the
suppression to the exact code locations that trigger false positives: delete the
'lib/structured_params.rb' entry from the Exclude list in the RuboCop RBS config
and add targeted inline disables (e.g. rubocop:disable
Style/RbsInline/UntypedInstanceVariable / rubocop:enable ...) around the
specific untyped instance-variable declarations inside the source file; keep or
retain the existing exclusion for structured_params/params only if that file
truly needs a full-file exemption.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.rubocop_rbs.yml:
- Around line 12-15: Remove the broad file-level exclusion for the
Style/RbsInline/UntypedInstanceVariable cop and instead scope the suppression to
the exact code locations that trigger false positives: delete the
'lib/structured_params.rb' entry from the Exclude list in the RuboCop RBS config
and add targeted inline disables (e.g. rubocop:disable
Style/RbsInline/UntypedInstanceVariable / rubocop:enable ...) around the
specific untyped instance-variable declarations inside the source file; keep or
retain the existing exclusion for structured_params/params only if that file
truly needs a full-file exemption.

In @.rubocop.yml:
- Around line 33-34: Don't relax Metrics/MethodLength globally; instead keep the
Max: 25 default and add a local suppression around the long method. Edit the
long method build_nested_label in lib/structured_params/i18n.rb and wrap it with
a rubocop disable/enable pair (rubocop:disable Metrics/MethodLength ...
rubocop:enable Metrics/MethodLength) so only build_nested_label is exempt while
the global cop remains strict.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3353fe63-a24a-48c9-8524-b3cc47a89ef1

📥 Commits

Reviewing files that changed from the base of the PR and between c4031d0 and df0ad50.

📒 Files selected for processing (12)
  • .rubocop.yml
  • .rubocop_rbs.yml
  • Steepfile
  • docs/installation.md
  • lib/structured_params.rb
  • lib/structured_params/i18n.rb
  • rbs_collection.lock.yaml
  • rbs_collection.yaml
  • sig/structured_params.rbs
  • sig/structured_params/i18n.rbs
  • sig/structured_params/type/array.rbs
  • spec/i18n_spec.rb
💤 Files with no reviewable changes (1)
  • rbs_collection.yaml

@Syati Syati merged commit c2d70b6 into main May 1, 2026
11 checks passed
@Syati Syati deleted the feature/i18n_cofigure branch May 1, 2026 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants